package com.ymttest.database.sqlwapper.shenqisettlement;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.SqTask;
import com.ymttest.utils.YMTDateUtil;

public class SqTaskWrapper {

	SqlManager manager;

    public SqTaskWrapper() {
        manager = new SqlManager("shenqisettlement");
    }
    
    @SuppressWarnings("unchecked")
	public SqTask selectByTaskTimeAndTaskType(Date task_time, String task_type) {
    	
    	HashMap<String, Object> map = new HashMap<>();
    	
    	map.put("task_time", task_time);
    	map.put("task_type", task_type);
    	
		List<SqTask> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.SqTaskMapper.selectByTaskTimeAndTaskType",
						map);
        manager.commit();
        
        if (result.size() == 0) {
			Logger.comment("更新数据失败");
		}
		
		return result.get(0);
    }
    
	public int updateByTaskTimeAndTaskTypeSelective(Date task_time, String task_type) {
    	
    	SqTask task = new SqTask();
    	
    	task.setTask_status((byte)0);
    	task.setTask_time(task_time);
    	task.setTask_type(task_type);
    	
    	int result = manager
                .update(
                        "com.ymttest.database.mapping.shenqisettlement.SqTaskMapper.updateByTaskTimeAndTaskTypeSelective",
                        task);
        manager.commit();
        
		if (result == 0) {
			Logger.comment("更新数据失败");
		}
		
		return result;
    }
    
    public static void main(String[] args) {
    	
    	SqTaskWrapper wrapper = new SqTaskWrapper();
    	
    	System.out.println(wrapper.selectByTaskTimeAndTaskType(YMTDateUtil.getDate(
				YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMD), "WITHDRAW"));
    }
}
